/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simulation2;

import java.util.Random;

/**
 *
 * @author cveilleux
 */
public class Dice {

    private int _faces;
    Random _random;

    private Integer _lastResult = null;

    public Dice() {
        this(6);
    }

    public Dice(int faces) {
        _faces = faces;
        _random = new Random();
    }

    public int getLastResult() {
        if (_lastResult == null)
            throw new IllegalStateException("No last result");

        return _lastResult.intValue();
    }

    public int throwDice() {
        Random rnd = new Random();
        _lastResult =  rnd.nextInt(_faces) + 1;
        return _lastResult.intValue();
    }

    @Override
    public String toString() {
        return "Dice [" + _lastResult + "]";
    }

}
